package user_controller

import (
	"gvb_service/common"
	"gvb_service/database"
	"gvb_service/util"

	"github.com/gin-gonic/gin"
)

func GetUserById(c *gin.Context) {
	common.Success(c, gin.H{"data": "user"}, "success")
}

func Adduser(c *gin.Context) {
	common.Success(c, gin.H{}, "success")
}

func GetUserList(c *gin.Context) {
	common.Success(c, gin.H{
		"list": []string{"user1", "user2", "user3"},
	}, "success")
}

func DeleteUserById(c *gin.Context) {
	common.Success(c, gin.H{}, "success")
}

func Logout(c *gin.Context) {
	token := c.GetHeader("token")
	if token == "" {
		common.Fail(c, gin.H{}, "token不能为空")
		return
	}
	username := util.ParseToken(token)
	if username == "" {
		common.Fail(c, gin.H{}, "token无效")
		return
	}
	if database.GetKey(username) == "" {
		common.Fail(c, gin.H{}, "token无效")
		return
	}
	if database.DelKey(username) {
		common.Success(c, gin.H{}, "退出成功")
	} else {
		common.Fail(c, gin.H{}, "退出失败")
	}
}
